package com.voyage.system.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.voyage.common.constant.BaseController;
import com.voyage.common.constant.PageMO;
import com.voyage.common.constant.ResponseMO;
import com.voyage.system.entity.MenuDO;
import com.voyage.system.service.MenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @Author: voyage
 * @Date: 2021-10-24
 * @Description: 菜单信息表前端控制器
 */
@RestController
@RequestMapping("/menu")
@Slf4j
@Api(tags = "菜单信息表")
public class MenuController extends BaseController{


    private final MenuService menuService;

    @Autowired
    public MenuController(MenuService menuService){
        this.menuService= menuService;
    }

    @GetMapping
    @ApiOperation(value = "查询列表")
    public ResponseMO<List<MenuDO>>list(){
        return success(menuService.list(null));
    }


    @PostMapping
    @ApiOperation(value = "插入")
    public ResponseMO insert(@Validated @RequestBody MenuDO menuDO){
        menuService.insert(menuDO);
        return success();
    }

    @PutMapping
    @ApiOperation(value = "更新")
    public ResponseMO update(@Validated @RequestBody MenuDO menuDO){
        menuService.update(menuDO);
        return success();
    }

    @DeleteMapping
    @ApiOperation(value = "删除")
    public ResponseMO delete(@RequestParam("id") Long id){
        menuService.delete(id);
        return success();
    }


    @PostMapping("/page")
    @ApiOperation(value = "分页查询")
    public ResponseMO<IPage<MenuDO>>page(@Validated @RequestBody PageMO pageMO){
        IPage<MenuDO> all=menuService.page(pageMO);
        return success(all);
    }

}

